from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SKUImage, SKU
from goods.models import SKUImage
from meiduo_admin.serializers.images import ImageSeriazlie, SKUSeriazlie
from meiduo_admin.utils import PageNum


class ImageView(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = SKUImage.objects.all()
    serializer_class = ImageSeriazlie
    pagination_class = PageNum

    def simple(self, request):
        skus = SKU.objects.all()
        ser = SKUSeriazlie(instance=skus, many=True)
        return Response(ser.data)


    def create(self, request, *args, **kwargs):
        data = request.data
        ser = self.get_serializer(data=data)
        ser.is_valid()
        file = request.FILES.get("image")
        return Response()
